package com.cyy.dyeing.common;

import java.util.*;

/**
 * @Author: cyy
 * @Date: 2024/7/26
 */
public class CommonUtils {
    private static String getYearMonth(Calendar c){
        int baseZeroMonth = c.get(Calendar.MONTH);
        return c.get(Calendar.YEAR) + "-" +
                (baseZeroMonth < 9 ? ("0" + (baseZeroMonth + 1)): String.valueOf(baseZeroMonth + 1));
    }
    public static Map<String, Object> getYearMonthList(){
        HashMap<String, Object> yearMonthMap = new HashMap<>();
        Calendar c = Calendar.getInstance();

        //本月
        yearMonthMap.put("currentYearMonth", getYearMonth(c));

        //下一个月
        c.add(Calendar.MONTH, 1);
        yearMonthMap.put("nextYearMonth", getYearMonth(c));
        ArrayList<String> list = new ArrayList<>();
        c.add(Calendar.MONTH, -13);
        for (int i = 0; i < 25; i++) {
            list.add(getYearMonth(c));
            c.add(Calendar.MONTH, 1);
        }
        yearMonthMap.put("list", list);
        return  yearMonthMap;
    }
}
